package com.wzx.user.service.impl;

import com.wzx.common.exception.LeadNewsException;
import com.wzx.common.util.encrypt.Md5Util;
import com.wzx.user.mapper.UserMapper;
import com.wzx.user.pojo.User;
import com.wzx.user.service.CommonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author wzx
 * @version 1.0
 * @date 2023/8/3 - 15:39
 * @description 标题
 */
@Service
public class CommonServiceImpl implements CommonService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public String encryption(Integer userId, String pwd) throws LeadNewsException {
        //1，查询用户信息
        User user = userMapper.selectById(userId);
        //2，返回加密后的密码
        return Md5Util.md5byKey(pwd, user.getSalt() + user.getUsername());
    }

    @Override
    public boolean decrypt(Integer userId, String pwd, String sqlPwd) throws LeadNewsException {
        //1，查询用户信息
        User user = userMapper.selectById(userId);
        //2，返回检验的账号密码是否正确
        return Md5Util.verifyByKey(pwd, sqlPwd, user.getSalt() + user.getUsername());
    }
}
